{% load bootstrap4 %}

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0", 
    shrink-to-fit=no>
  <title>Blogs</title>

  {% bootstrap_css %}
  {% bootstrap_javascript jquery='full' %}

</head>

<body>

  <nav class="navbar navbar-expand-md navbar-light bg-light mb-4 border">

    <a class="navbar-brand" href="{% url 'blogs:home' %}">BlogHome</a>

    <button class="navbar-toggler" type="button" data-toggle="collapse" 
      data-target="#navbarCollapse" aria-controls="navbarCollapse" 
      aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarCollapse">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item">
          <a class="nav-link" href="{% url 'blogs:blogs' %}">Blogs</a>
        </li>
      </ul>

      <ul class="navbar-nav ml-auto">
        {% if user.is_authenticated %}
          <li class="nav-item d-flex align-items-center"> <!--将元素垂直居中-->
            <span class="nav-link">Hello, {{ user.username }}.</span>
            <form method="post" action="{% url 'users:logout' %}" 
              style="display:inline;">
              {% csrf_token %}
              <button type="submit" class="btn btn-link nav-link p-0" 
                >Log out</button>
            </form>
          </li>
  
        {% else %}
          <li class="nav-item">
            <a class="nav-link" href="{% url 'users:register' %}">Register</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="{% url 'users:login' %}">Login</a>
          </li>
        {% endif %}
      </ul>
    </div>

  </nav>

  <main role="main" class="container">
    <div class="pb-2 mb-2 border-bottom">
      {% block page_header %}{% endblock page_header %}
    </div>
    <div>
      {% block content %}{% endblock content %}
    </div>
  </main>

</body>

</html>